﻿#!/usr/bin/env python3

import pickle

class Car:
    def __init__(self, logo, category):
        self.logo = logo
        self.category = category
    def show(self):
        print("logo:{0}, category:{1}".format(self.logo, self.category))

def main():
    '''pickle -  object serialization
pickle只能保存有名字关联的数据,无法保存包括代码等无名字相关联的内容.    '''
    print(main.__doc__)
    print("="*30)

    car = Car("GW", "SUV")
    car.show()
    f = open("car.txt", "wb")
    pickle.dump(car, f)
    f.close()

    f = open("car.txt", "rb")
    car2 = pickle.load(f)
    f.close()
    car2.show()



if __name__=='__main__':
    main()
